﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace WebBanHang.GUI
{
    public partial class Product_By_ID : System.Web.UI.Page
    {
        public string Datestring;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadSP();
            }
        }
        void LoadSP()
        {
            if (Request.QueryString["ID"] != null)
            {
                string id = Request.QueryString["ID"].ToString();
                string sql;
                if (id == "0")
                {
                    sql = "Select * from DEAL where NgayKetThuc>=@NgayHienTai";
                }
                else
                {
                    sql = "Select * from DEAL where NgayKetThuc>=@NgayHienTai and MaLoai = " + id;
                }
                SqlCommand cmd = new SqlCommand(sql);
                SqlParameter[] pr = { new SqlParameter("@NgayHienTai", DateTime.Now.Date) };
                DataTable DATA = new DataTable();
                DATA = DataProvider.LoadTable(cmd, pr);
                dlDeal.DataSource = DATA;
                dlDeal.DataBind();
                if (DATA.Rows.Count > 0)
                {
                    string format = "ddd MMM d yyyy HH:mm:ss";
                    DateTime _TempDate = Convert.ToDateTime(DATA.Rows[0]["NgayKetThuc"]);
                    Datestring = _TempDate.ToString(format);
                }
            }
            else
            {
                //string url = ViewState["RefUrl"] == null ? "~/GUI/Home.aspx" : ViewState["RefUrl"].ToString();
                Response.Redirect("~/GUI/Home.aspx");
            }
        }

        protected void dlDeal_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}